package longyiqun.killwife.util;

import longyiqun.killwife.entity.User;
import org.hibernate.annotations.SQLDelete;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by longyiqun on 07/03/2017.
 */

public interface UserRepository extends JpaRepository<User, Long> {

    @Query("from User u where u.id=:id")
    User findByID(@Param("id") int id);


    List<User> findByName(String name);

    @Modifying
    @Transactional
    @Query("delete from User u where u.id=:id")
    int deleteByID(@Param("id") int id);


    @Modifying
    @Transactional
    @Query("update User u set u.name=:name, u.age=:age where u.id=:id")
    int updateUser(@Param("name") String name, @Param("age") int age, @Param("id") int id);

}
